Windows Azure Mobile Services authentication with social identity providers


Windows Runtime
azure mobile services
Windows RT
en-US
11/25/2013

This sample shows how Windows Azure Mobile Services enables your Windows Store apps to authenticate with well known social identity providers such as Microsoft accounts, Facebook, Twitter, and Google.

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.

Related topics

free Windows Azure trial
Get started with authentication in Mobile Services
Windows Azure management portal
Windows app samples

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2

Build the sample

  1. If you do not have a Windows Azure subscription, sign up for a free Windows Azure trial.
  2. Install the Windows Azure command line tools.
  3. Open a command prompt to download the required credentials to communicate with Windows Azure as follows. This is a one-time setup for running all subsequent commands to manage Mobile Services:
    1. Download Windows Azure management credentials with this command: azure account download.                   This will display a web page for you to sign in to the Windows Azure management portal. After you sign in, Windows Azure will prompt you to download a publish settings file for your Windows Azure subscription. Save this file to your local computer.
    2. Import the publish settings file from this location with this command: azure account import [SavedLocation]. This will configure your command prompt to manage all of your Windows Azure services from the command line.
  4. Create a Windows Azure Mobile Service with this command: azure mobile create [AzureMobileServiceName] [sqlAdminUsername] [sqlAdminPassword]
  5. Go to Get started with authentication in Mobile Services, and follow the instructions to register your Windows Azure Mobile Service with the respective social identity provider, such as Microsoft accounts, Facebook, Twitter, or Google. Make note of the client ID and client secret values that the provider supplies to you for your Windows Azure Mobile Service.
  6. Update your Windows Azure Mobile Service with the client ID and client secret values by using one of these sets of commands:

    Microsoft accounts

    • azure mobile config set [AzureMobileServiceName] microsoftAccountClientID [ClientId]
    • azure mobile config set [AzureMobileServiceName] microsoftAccountClientSecret [ClientSecret]

    Facebook

    • azure mobile config set [AzureMobileServiceName] facebookClientID [AppId]
    • azure mobile config set [AzureMobileServiceName] facebookClientSecret [AppSecret]

    Twitter

    • azure mobile config set [AzureMobileServiceName] twitterClientID [ConsumerKey]
    • azure mobile config set [AzureMobileServiceName] twitterClientSecret [ConsumerSecret]

    Google

    • azure mobile config set [AzureMobileServiceName] googleClientID [ClientId]
    • azure mobile config set [AzureMobileServiceName] googleClientSecret [ClientSecret]
  7. Get the ApplicationUrl and ApplicationKey for your Windows Azure Mobile Service with this command: azure mobile show [AzureMobileServiceName]
  8. Install the Windows Azure Mobile Services NuGet package.
  9. Open the App.xaml.cs file and replace "mobile-service-url" and "mobile-service-key" with the ApplicationUrl and ApplicationKey. Your Windows Store app is now configured to communicate with your created Windows Azure Mobile Service.
  10. Click Build > Build Solution.

Run the sample

  1. To debug the app and then run it in Microsoft Visual Studio, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
  2. After the app starts, select the authentication provider that you configured for your app, and click Launch. An authentication dialog box for the respective provider appears, prompting you to enter the credentials for the provider. After you enter the credentials and sign in for the first time, a consent dialog box appears, requesting access to the app. After you consent, and your credentials are authenticated by the provider, the user ID is shown in the output area.
  3. You can also go to the Windows Azure management portal, sign in, and view your Windows Azure Mobile Service.